package com.example.myrecyclerview.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.myrecyclerview.R;

public class NewsFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_news, container, false);
        WebView webView = root.findViewById(R.id.webView);
        webView.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return super.shouldOverrideUrlLoading(view,url);
            }
        });
        WebSettings settings = webView.getSettings();
        settings.setJavaScriptEnabled(true);    //允许js
//        settings.setUseWideViewPort(false); // 将图片调整到适合webview的大小
//        settings.setLoadWithOverviewMode(true);  // 缩放至屏幕的大小
//        settings.setSupportZoom(true);//启用缩放功能
//        settings.setBuiltInZoomControls(true);//使用WebView内置的缩放功能
//        settings.setDisplayZoomControls(true);//隐藏屏幕中的虚拟缩放按钮
//        settings.setTextZoom(100);//字体百分比，替代原API:setTextSize
        try {
            // load the url
            webView.loadUrl("https://news.sina.cn/");
        } catch (Exception e) {
            e.printStackTrace();
        }

        return root;
    }
}
